package keke.ai.code.mother.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import keke.ai.code.mother.exception.BizException;
import keke.ai.code.mother.exception.ErrorCode;
import keke.ai.code.mother.model.entity.User;
import keke.ai.code.mother.model.vo.user.UserVo;
import keke.ai.code.mother.service.UserService;
import keke.ai.code.mother.mapper.UserMapper;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author 86158
 * @description 针对表【user(用户)】的数据库操作Service实现
 * @createDate 2025-08-04 16:12:49
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {

    @Override
    public UserVo findUserByUserName(String username) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_name", username);

        User user = baseMapper.selectOne(queryWrapper);

        if(Objects.isNull(user)) {
            throw new BizException(ErrorCode.SYSTEM_ERROR, "用户不存在");
        }

        UserVo userVo = new UserVo();
        BeanUtil.copyProperties(user, userVo);
        return userVo;
    }
}




